<?php

class Controller
{
    public static $start_row = 0;//分页起始行
    public static $rows = 0;//分页行数
    public static $method = '';
    public static $module = '';
    public static $controller = '';
    /**配全easyui使用
     *
     * @param string $rows
     * @param string $total
     */
    static function successExit(  $data = null, $msg = null, $msg_code = null )
    {
        exit( json_encode( [ 'issuccess' => 'true','data' => $data, 'msg' => $msg, 'msg_code' => $msg_code ], JSON_UNESCAPED_UNICODE ) );
    }

    /**
     * @param null $msg
     * @param null $msg_code
     * @param null $data
     */
    static function failExit( $msg = null, $msg_code = null, $data = null )
    {
        if ( is_array( $msg ) ) {
            $msg_arr = $msg;
            $msg = $msg_arr[ 'msg' ];
            $msg_code = $msg_arr[ 'msg_code' ];
            $data = $msg_arr[ 'data' ];
        }
        exit( json_encode( [ 'issuccess' => 'false', 'msg' => $msg, 'msg_code' => $msg_code, 'data' => $data ], JSON_UNESCAPED_UNICODE ) );
    }

    static function allExit( array $exit_info )
    {
        if ( $exit_info[ 'isok' ] ) {
            unset( $exit_info[ 'isok' ] );
            $rows = [ ];
            $total = '';
            if ( isset( $exit_info[ 'data' ][ 'rows' ] ) ) {
                $rows = $exit_info[ 'data' ][ 'rows' ];
                unset( $exit_info[ 'data' ][ 'rows' ] );
            }
            if ( isset( $exit_info[ 'data' ][ 'total' ] ) ) {
                $total = $exit_info[ 'data' ][ 'total' ];
                unset( $exit_info[ 'data' ][ 'total' ] );
            }
            self::successExit( $rows, $total, $exit_info[ 'data' ] );
        } else
            self::exitError( $exit_info );
    }

}